package site.immonkey.dbtool.datasource;

import java.beans.PropertyVetoException;
import java.util.Map;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

import site.immonkey.dbtool.beans.DataSourceConfig;

public class C3P0DataSourceAdapter extends DataSourceAdapter {
	@Override
	protected DataSource adapter(DataSourceConfig config) {
		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		dataSource.setUser(config.getUsername());
		dataSource.setPassword(config.getPassword());
		try {
			dataSource.setDriverClass(config.getDriverClass());
		} catch (PropertyVetoException e) {
			throw new RuntimeException(e);
		}
		dataSource.setJdbcUrl(config.getJdbcUrl());
		return dataSource;
	}
	
	@Override
	protected DataSource adapter(Map<String, String> config) {
		ComboPooledDataSource dataSource = new ComboPooledDataSource();
		injectProperty(dataSource, config);
		return dataSource;
	}
}
